cmake_minimum_required(VERSION 3.10)
project(cskynet)

# 设置 C++ 编译标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置编译选项
set(CMAKE_CXX_FLAGS "-Wno-misleading-indentation -rdynamic -ffunction-sections -fdata-sections -pthread")

# 设置执行文件输出目录
set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/../../../bin/")

# 根据选项设置 Release 和 Debug 版本的选项
if(CMAKE_BUILD_TYPE STREQUAL "Release")
    # Release 版本
    message("Building Release version")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -DNDEBUG -Wall -Wextra")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message("Building Debug version")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -Wextra -pg")
else()
    # Debug 版本
    message("Building Debug Memory version")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -Wall -Wextra  -pg -fsanitize=address -fsanitize-recover=address")
endif()

# 指定源文件目录
aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}" SOURCES)

# 添加头文件目录
include_directories(
    /usr/local/include
)

# 添加可执行文件
add_executable(${PROJECT_NAME} ${SOURCES})

# 查找 OpenSSL 库
find_package(OpenSSL REQUIRED)

find_package(fmt REQUIRED)

# 连接相关库文件
set(LIBRARY_LIST 
    OpenSSL::SSL 
    OpenSSL::Crypto 
    pthread 
    z 
    rt 
    jemalloc 
    lua
    ssl 
    crypto
    fmt::fmt
    dl
)

target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBRARY_LIST})